package com.tony.study.designMode.DM3_单例模式;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: Singleton3
 * @Auther: 皮蛋布丁
 * @Date: 2021/11/01/16:30
 * @Description: 单例模式（线程安全，只在第一次创建实例的时候加锁）
 */
public class Singleton3 {

    //私有构造器，防止外部new实例
    public Singleton3() {
    }
    private static Singleton3 instance = null;

    public static Singleton3 getInstance() {
        if (instance == null) {
            synchronized (Singleton3.class) {
                if (instance == null) {
                    instance = new Singleton3();
                }
            }
        }
        return instance;
    }

    public void show() {
        System.out.println("你好，我是双重校验锁单例模式！");
    }
}
